@extends('home/main/layout')
@section('title','订单处理')
@section('introduce')

@stop
@section('content')
<!--bottom-header-->
	<!--start-breadcrumbs-->
	<div class="breadcrumbs">
		<div class="container">
			<div class="breadcrumbs-main">
				<ol class="breadcrumb">
					<li><a href="{{asset('/')}}">首页</a></li>
					<li class="active">订单处理</li>
				</ol>
			</div>
		</div>
	</div>
	<!--end-breadcrumbs-->
	<br>
	<form action="/orderadd" method="post">
		{{csrf_field()}}
		<!--收货地址-->
		<div class="container">
		<h3>收货地址</h3><br>
		<a href="/myhouse/address">
		<button type="button" class="btn btn-success">添加收货地址</button>
		</a>
		<a href="#">
		<button type="button" class="btn btn-primary">管理收货地址</button>
		</a>
		<div class="form-group">
		@foreach($rec_adds as $rec_add)
	     <div class="radio">
	        <label>
	          <input type="radio" name="rec_add" fre="{{$rec_add->freight}}" value="{{$rec_add->rec_add_id}}" class="recadd"><span>
	           {{$rec_add->region_name}} &nbsp;&nbsp;{{$rec_add->con_address}} </span>（ <span>{{$rec_add->consignee}}</span> 收 ）&nbsp;&nbsp;<span>{{$rec_add->con_phone}}</span>
	        </label>
	      </div>
	    @endforeach
	    </div>
	    </div>
	    <hr>
		<!--支付方式-->
	    <div class="container">
		<h3>支付方式</h3><br>
		<div class="form-group">
		@foreach($payment_modes as $payment_mode)
	      <div class="radio">
	        <label>
	          <input type="radio" name="pay_mod" value="{{$payment_mode->pay_mod_id}}">
	          <span>{{$payment_mode->name}}</span>&nbsp;&nbsp;{{$payment_mode->description}}
	        </label>
	      </div>
	    @endforeach
	    </div>
	    </div>
		<hr>

		<div class="container">
			<h3>订单详细</h3><br>
			<div class="table-responsive">
        	<table id="carttable" class="table table-bordered table-striped text-center">
	          <thead>
	          <tr>
	            <th colspan="2">商品信息</th>
	            <th>购买数量</th>
	            <th>商品单价(物流价)(元)</th>
	            <th>小计(元)</th>
	          </tr>
	          </thead>
	          <tbody>
	          	@foreach($orderpros as $orderpro)
	          	<tr>
	          		<input type="hidden" name="cart_id[]" value="{{$orderpro->cart_id}}"/>
					<td><a href="/single/{{$orderpro->pro_id}}"><img src="/uploads/product/logo_pic/{{$orderpro->logo_pic}}" style="width:50px;heihgt:50px;"></a></td>
					<td>
						<a href="/single/{{$orderpro->pro_id}}">{{$orderpro->title}}</a><br>
						<span>{{$orderpro->pro_keyword}}</span>
					</td>
					<td class="count">{{$orderpro->buynum}}</td>
					<td>{{$orderpro->sprice}}（{{$orderpro->lprice}}）</td>
					<td class="sp">{{($orderpro->sprice+$orderpro->lprice)*$orderpro->buynum}}</td>
	          	</tr>
	          	@endforeach
	          </tbody>
        	  <tfoot>
        	  	<tr>
        	  		<th colspan="5"></th>
        	  	</tr>
        	  	<tr>
        	  		<th>
        	  			订单留言
        	  		</th>
        	  		<th colspan="2">
						<textarea name="ordermessage" style="resize:none;width:500px;"></textarea>
        	  		</th>
        	  		<th colspan="2">商品合计（元）：<span id="pro_price"></span></th>
        	  	</tr>
        	  	<tr>
        	  		<th colspan="5"></th>
        	  	</tr>
        	  	<tr>
        	  		<th colspan="3">
						寄送至：<span id="sendto"></span><br>
						收货人：<span id="con_name"></span> <span id="con_phone"></span><br>
						运费：￥<span id="allfre"></span><br>
						支付方式：<span id="paymod"></span>
						<br>
						发货时间：卖家承诺订单在买家付款后，72小时内发货
        	  		</th>
        	  		
        	  		<th colspan="2">
        	  			总金额：￥<span id="allmoney"></span><br>
        	  			<button class="btn btn-warning" id="ordercommit">提交订单</button>
        	  		</th>
        	  		<script>
        	  			$(function(){
        	  				//地址
        	  				$('.recadd').first().prop('checked',true);
        	  				$('.recadd').first().attr('checked',true);
        	  				var oadd=$('.recadd').first().next().html();
        	  				//console.log(oadd);
        	  				
        	  				$('#sendto').html(oadd);
        	  				var oconname=$('.recadd').first().next().next().html();
        	  				var oconphone=$('.recadd').first().next().next().next().html();
        	  				$('#con_name').html(oconname);
        	  				$('#con_phone').html(oconphone);

        	  				

        	  				$('.recadd').on('click',function(){
        	  					var add=$(this).next().html();
        	  					$('#sendto').html(add);
        	  					var name=$(this).next().next().html();
        	  					var phone=$(this).next().next().next().html();
        	  					$('#con_name').html(name);
        	  					$('#con_phone').html(phone);
        	  					var freight=$(this).attr('fre');
        	  					//console.log(freight);
        	  				});

        	  				//支付方式
        	  				$('[name=pay_mod]').first().prop('checked',true);
        	  				$('[name=pay_mod]').first().attr('checked',true);
        	  				var opm=$('[name=pay_mod]').first().next().html();
        	  				$('#paymod').html(opm);
        	  				$('[name=pay_mod]').on('click',function(){
        	  					var pm=$(this).next().html();
        	  					$('#paymod').html(pm);
        	  					
        	  				});
        	  				//商品合计
        	  				var price=new Array();	
		            		if($('[class=sp]').length!=0){

			            		for(i=0;i<=$('[class=sp]').length-1;i++){
			            			price[i]=$('[class=sp]').eq(i).html();
			            		}
			            		//console.log(price);
		            			var proprice=eval(price.join('+'));
		            			$('#pro_price').html(proprice);
		            		}
        	  				//商品总数
        	  				var buynums=new Array();	
		            		if($('[class=count]').length!=0){

			            		for(i=0;i<=$('[class=count]').length-1;i++){
			            			buynums[i]=$('[class=count]').eq(i).html();
			            		}
		            			var procount=eval(buynums.join('+'));
		            			//console.log(procount);
		            		}
		            		//运费
        	  				var freight=$('.recadd').first().attr('fre');
        	  				var mol=Math.ceil(procount/5);
        	  				var allfreight=mol*freight;
							$('#allfre').html(allfreight);
							$('#allmoney').html(allfreight+proprice);
							$('.recadd').on('click',function(){
        	  					
        	  					var freight=$(this).attr('fre');
        	  					//console.log(freight);
        	  					var allfreight=mol*freight;
								$('#allfre').html(allfreight);
								$('#allmoney').html(allfreight+proprice);
        	  				}); 
							
							
							


        	  			});
        	  		</script>
        	  	</tr>
        	  </tfoot>
        	</table>
       		</div>
       	</div>
		<hr>
		
	</form>
@stop
